package com.itboye.ihomebank.presenter;

import com.itboye.ihomebank.base.BasePresenter;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.interfaces.IElectricMeterInterface;
import com.itboye.ihomebank.responsitory.ElectricMeterRepository;

import java.util.Observer;

/**
 * Created by Administrator on 2018/8/31 0031.
 */

public class ElectricMeterPresenter extends BasePresenter implements IElectricMeterInterface {

    //电表分页
    public static String BY_Emeter_query_success = "_BY_Emeter_query_success";
    public static String BY_Emeter_query_fail = "_BY_Emeter_query_fail";

    //我的电表
    public static String BY_Emeter_address_success = "_BY_Emeter_address_success";
    public static String BY_Emeter_address_fail = "_BY_Emeter_address_fail";

    //电表详情
    public static String BY_Emeter_detail_success = "_BY_Emeter_detail_success";
    public static String BY_Emeter_detail_fail = "_BY_Emeter_detail_fail";

    //电表拉合闸
    public static String BY_Emeter_switchFlag_success = "_BY_Emeter_switchFlag_success";
    public static String BY_Emeter_switchFlag_fail = "_BY_Emeter_switchFlag_fail";

    //电表单属性更改
    public static String BY_Emeter_editField_success = "_BY_Emeter_editField_success";
    public static String BY_Emeter_editField_fail = "_BY_Emeter_editField_fail";

    //电表整改
    public static String BY_Emeter_edit_success = "_BY_Emeter_edit_success";
    public static String BY_Emeter_edit_fail = "_BY_Emeter_edit_fail";

    //电表同步
    public static String AM_Emeter_sync_success = "_AM_Emeter_sync_success";
    public static String AM_Emeter_sync_fail = "_AM_Emeter_sync_fail";

    //电费/充值  每月
    public static String BY_Emeter_feeMonth_success = "_BY_Emeter_feeMonth_success";
    public static String BY_Emeter_feeMonth_fail = "_BY_Emeter_feeMonth_fail";

    //电费 每天
    public static String BY_Emeter_feeDaily_success = "_BY_Emeter_feeDaily_success";
    public static String BY_Emeter_feeDaily_fail = "_BY_Emeter_feeDaily_fail";

    public ElectricMeterPresenter(Observer observer) {
        super(observer);
    }


    @Override
    public void queryEmeter(String field, String order, String page, String size, String kword) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_query_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_query_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.queryEmeter(field, order, page, size, kword);

    }

    @Override
    public void queryMyEmeter(String uid, String kword,String sort) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_address_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_address_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.queryMyEmeter(uid, kword,sort);
    }

    @Override
    public void emeterDetaile(String uid, String eid) {


        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_detail_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_detail_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.emeterDetaile(uid, eid);
    }

    @Override
    public void bindHouseNo(String uid, String eid, String house_no, String house_people) {

    }

    @Override
    public void unbindHouseNo(String uid, String eid, String house_no) {

    }

    @Override
    public void emeterPullOff(String uid, String eid, String op_type) {
        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_switchFlag_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_switchFlag_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.emeterPullOff(uid, eid, op_type);

    }

    @Override
    public void emeterEditField(String uid, String eid, String field, String value) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_editField_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_editField_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.emeterEditField(uid, eid, field, value);
    }

    @Override
    public void emeterEdit(String uid, String eid, String name, String price, String fee_type, String house_people) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_edit_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_edit_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.emeterEdit(uid, eid, name, price, fee_type, house_people);
    }

    @Override
    public void emeterSyn(String time, String sync) {
        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(AM_Emeter_sync_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(AM_Emeter_sync_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.emeterSyn(time, sync);

    }

    @Override
    public void feeMonth(String uid, String start, String end, String fresh) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_feeMonth_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_feeMonth_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.feeMonth(uid, start, end, fresh);
    }

    @Override
    public void feeDaily(String uid,String aid, String start, String end, String fresh) {

        IElectricMeterInterface emeter = new ElectricMeterRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_feeDaily_success);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(BY_Emeter_feeDaily_fail);
                        ElectricMeterPresenter.this.setChanged();
                        ElectricMeterPresenter.this.notifyObservers(result);

                    }
                });
        emeter.feeDaily(uid, aid,start, end, fresh);
    }
}
